package pers.qianyu.module.core.domain.system.converter;


import com.baomidou.mybatisplus.extension.plugins.pagination.*;
import org.springframework.stereotype.*;
import pers.qianyu.module.core.comm.*;
import pers.qianyu.module.core.domain.system.dto.*;
import pers.qianyu.module.core.domain.system.entity.*;
import pers.qianyu.module.core.domain.system.vo.*;

import java.util.*;
import java.util.stream.*;

/**
 * @author mizzle rain
 * @date 2020-11-13 12:36
 */
@Component
public class SysRoleConverter extends BaseConverter {
    public SysRoleVO convertToVO(SysRolePO sysRolePO) {
        SysRoleVO sysRoleVO = new SysRoleVO();
        sysRoleVO.setRoleName(sysRolePO.getRoleName());
        sysRoleVO.setRoleKey(sysRolePO.getRoleKey());
        sysRoleVO.setStatus(sysRolePO.getStatus());
        entityToVO(sysRolePO, sysRoleVO);
        return sysRoleVO;
    }

    public SysRolePO convertToPO(SysRoleDTO sysRoleDTO) {
        SysRolePO sysRolePO = new SysRolePO();
        sysRolePO.setRoleName(sysRoleDTO.getRoleName());
        sysRolePO.setRoleKey(sysRoleDTO.getRoleKey());
        sysRolePO.setStatus(sysRoleDTO.getStatus());
        return sysRolePO;
    }

    public Pagination<SysRoleVO> convertToPagination(Page<SysRolePO> rolePOPage) {
        Pagination<SysRoleVO> pagination = new Pagination<>();
        pagination.setCurrent(rolePOPage.getCurrent());
        pagination.setTotal(rolePOPage.getTotal());
        pagination.setSize(rolePOPage.getSize());
        pagination.setRecords(Optional.ofNullable(rolePOPage.getRecords())
                .map(List::stream)
                .orElseGet(Stream::empty)
                .map(this::convertToVO)
                .collect(Collectors.toList()));
        return pagination;
    }

    public List<SysRoleVO> convertToVOS(List<SysRolePO> sysRolePOS) {
        return Optional.ofNullable(sysRolePOS)
                .map(List::stream)
                .orElseGet(Stream::empty)
                .map(this::convertToVO)
                .collect(Collectors.toList());
    }
}
